<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<c:set var="base" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>设备管理</title>
  <link href="${base}/assets/css/public.css" rel="stylesheet">
  <script src="${base}/assets/js/jquery.min.js"></script>
  <link rel="stylesheet" type="text/css" href="${base}/assets/easyui/themes/gray/easyui.css" />
  <link rel="stylesheet" type="text/css" href="${base}/assets/easyui/themes/icon.css" />
  <script type="text/javascript" src="${base}/assets/easyui/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="${base}/assets/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>

<div class="top">
   <c:import url="../commons/top.jsp"/>
</div>
<div class="wrap">
  <div class="side">
   	<c:import url="../commons/sidebar.jsp"/>
  </div>
  <div class="cont">
    <div class="bread">
      <span>用户管理</span><span>&nbsp;&gt;&nbsp;</span><span>添加用户</span>
      <div class="excel-add">
      		<a class="add" style="float: right;margin-right: 30px;" href="javascript:void(0)" onclick="fahui()">返回</a>
      </div>      
      <div class="clear"></div>
    </div>
<form method="post" action="${base}/back/userAdd.do" id="donaForm">
    <div class="form-group">
        <label>车间名称:</label>
        <div class="group-add">
            <input id="workname" name="workname" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>用户姓名:</label>
        <div class="group-add">
            <input name="uname"  class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>联系方式:</label>
        <div class="group-add">
            <input name="uphone" class="easyui-validatebox" data-options="required:true, validType:'maxLength[15]'" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>登录账号:</label>
        <div class="group-add">
            <input id="uacc" name="uacc" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>用户密码:</label>
        <div class="group-add">
            <input name="passw" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>账号备注：</label>
        <div class="group-add">
            <textarea name="remark" class="easyui-validatebox" style="width:50%" data-options="required:true" rows="3" cols="93" placeholder="账号备注"></textarea>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-actions">
      <a class="btn" style="background-color:#337ab7; color:#fff" onclick="submitDona()">提交</a>
    </div>
</form>
  </div>
</div>
<div class="clear"></div>
<script type="text/JavaScript">
$("#uacc").change(function() { 
	var uacc = $.trim($("#uacc").val());
	   $.ajax({
        type: "POST",
        dataType: "json", // 数据格式:JSON
        url: '${base}/back/uacccheck.do?uacc='+uacc,
       // data: postData,
        success: function (data) {
     	   if(data.ok == 'ok'){ 
     	   }else{
     		   alert("登录账号已存在！！")
     		   return;
     	   }
        }  
    });
});
function submitDona(){
 var nwhn = $.trim($("#workname").val());
 $.ajax({
        type: "POST",
        dataType: "json", // 数据格式:JSON
        url: '${base}/back/whnamecheck.do',
        data: {whname:nwhn},
        success: function (data) {
     	   if(data.ok == 'ok'){
     		   var mymessage=window.confirm('新的车间名称，是否建立新的车间分类？');  
     		    if(mymessage==true){  
     		    	ajaxsubmitDona();  
     		    }else if(mymessage==false){  
     		    	 return; 
     		    }  
     	   }else{
     		   ajaxsubmitDona();
     	   }
        }      
    });
}  
function ajaxsubmitDona(){
 var postData = $('#donaForm').serialize();
 $.ajax({
     type: "POST",
     dataType: "json", // 数据格式:JSON
     url: '${base}/back/useradd.do',
     data: postData,
     success: function (data) {
    	 var mymessage=window.confirm('添加成功！是否返回');  
		 if(mymessage==true){  
		   	fahui();
		 }else if(mymessage==false){  
		   	return; 
		 }
     }
 });
}
function fahui(){
	var url ="${base}/back/userlist.do";
	window.location.href = url;
}
</script>
</body>
</html>